$(function() {
	$("#footer").load('footer.html', function(data, status, xhr) {});
	var code = ""; //接收验证码   
	$('#code-btn').click(function() {
		var count = 5;
		var phone = $("#phone").val(); //手机号码  
		var reg_phone = /^1[34578]\d{9}$/;
		console.log(reg_phone.test(phone))
		if(!reg_phone.test(phone)) { //验证手机是否符合格式
			easyDialog.open({
				container: {
					content: '请填写正确的手机号！'
				},
				autoClose: 1500
			});
			return false;
		}
		console.log($("input[type='checkbox']").attr('checked'));
		//开始计时  
		$("#code-btn").attr('disabled', 'disabled');
		$("#code-btn").html(count + "秒后发送");
		var timer = setInterval(function() {
			count--;
			$("#code-btn").html(count + "秒后发送");
			if(count == 0) {
				clearInterval(timer);
				$("#code-btn").attr("disabled", false); //启用按钮  
				$("#code-btn").html("重新发送");
				code = ""; //清除验证码。如果不清除，过时间后，输入收到的验证码依然有效 
			}
		}, 1000);

		//向后台发送处理数据  
		$.ajax({
			type: "POST",
			dataType: "text",
			url: host + '/MtmlAPI/regissend',
			data: {
				moblie: phone
			},
			error: function(XMLHttpRequest, textStatus, errorThrown) {},
			success: function(msg) {}
		});
	});

	$('#resiger').click(function() {
		var phone = $('#phone').val()
		var pwd = $('#pwd').val();
		var code = $('#checkCode').val();
		var checked = $('#Agree').is(":checked")
		if(!phone) {
			easyDialog.open({
				container: {
					content: '手机号不能为空！'
				},
				autoClose: 1500
			});

		} else if(!pwd) {
			easyDialog.open({
				container: {
					content: '密码不能为空！'
				},
				autoClose: 1500
			});

		} else if(!code) {
			easyDialog.open({
				container: {
					content: '验证码不能为空！'
				},
				autoClose: 1500
			});
		} else if(!checked) {
			easyDialog.open({
				container: {
					content: '请勾选协议！'
				},
				autoClose: 1500
			});
		} else {
			$.ajax({
				url: host + '/MtmlAPI/Register',
				type: 'POST',
				data: {
					phone: phone,
					pwd: pwd,
					Value: code,
					cid: cid
				},
				dataType: 'JSON',
				success: function(data) {
					if(data.state) {
						if(data === null) {
							easyDialog.open({
								container: {
									content: data.message
								},
								autoClose: 1500
							});
						} else {
							easyDialog.open({
								container: {
									content: '已成功注册！'
								},
								autoClose: 1500
							});
							window.location.href = 'login.html';
						}

					} else {
						easyDialog.open({
								container: {
									content: data.message
								},
								autoClose: 1500
							});
					}
				}
			})
		}
	})

})